
import React,{useState,useEffect} from 'react'
import axios from 'axios'
export default function Mess() {
  let [mess,setmess]=useState([])

  let getMess=async()=>{
    let val=await axios.get("http://127.0.0.1:3000/xuweixin/messshow")
    setmess(val.data.datas)
  }
  
  useEffect(()=>{
    getMess()
  },[])

  return (
    <div>
        {
          mess.map(item=>(
            <div key={item._id}>
                <p><img style={{widt:"200px",height:"150px"}} src={item.img}></img></p>
                <p>{item.name}</p>
                <p>{item.price}</p>
                <p>{item.specTitle}</p>
                <p>{item.salesnum}</p>

                <button
                  onClick={async ()=>{
                      let adminmess=JSON.parse(localStorage.getItem("adminmess"))
                     let vals=await axios.post("http://127.0.0.1:3000/xuweixin/addcar",{
                           _id:item._id,
                           name:item.name,
                           price:item.price,
                           buynum:1,
                           img:item.img,
                           flag:false,
                           mess:item.specTitle,
                           uid:adminmess._id,
                           shoppid:item._id
                      })
                      if(vals.data.code==200){
                        getMess()
                      }
                  }}
                >加入购物车(0)</button>
            </div>
          ))
        }
    </div>
  )
}
